package com.zhongyong.server.process;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.common.entity.Car;
import com.common.entity.DataPack;
import com.common.entity.Employee;
import com.common.entity.PayType;
import com.common.server.view.ServerMainFrame;
import com.common.server.view.ServerProcessThread;
import com.common.server.view.ServiceProcess;
import com.zekai.dao.impl.EmployeeDaoImpl;
import com.zekai.server.IEmployeeSevice;
import com.zekai.server.dao.impl.EmployeeSeviceImpl;
import com.zhongyong.server.dao.CarDao;
import com.zhongyong.server.dao.PayTypeDao;
import com.zhongyong.server.dao.impl.CarDaoImpl;
import com.zhongyong.server.dao.impl.PayTypeDaoImpl;

public class PayTypeServiceProcess implements ServiceProcess{

	@Override
	public Object service(DataPack dataPack, ServerProcessThread serverProcessThread, ServerMainFrame serverMainFrame)
			throws IOException {
		PayTypeDao payTypeDao = new PayTypeDaoImpl();
		if("addPayType".equals(dataPack.getOptType())) {
			PayType pt = new PayType();
			pt = (PayType) dataPack.getCon();
			int rows = payTypeDao.savePayType(pt);
			DataPack p1 = new DataPack();
			p1.setCon(rows);
			p1.setOptType(dataPack.getOptType());	
			serverProcessThread.getOos().writeObject(p1);
			serverProcessThread.getOos().flush();
			
			
		}
		else if("updatePayType".equals(dataPack.getOptType())){
			PayType pt = new PayType();
			pt = (PayType) dataPack.getCon();
			int rows = payTypeDao.updatePayType(pt);
			DataPack p1 = new DataPack();
			p1.setCon(rows);
			p1.setOptType(dataPack.getOptType());	
			serverProcessThread.getOos().writeObject(p1);
			serverProcessThread.getOos().flush();
			
		}
		else if("getInfo".equals(dataPack.getOptType())) {
			List<PayType> pts = new ArrayList<>();
			pts = payTypeDao.getInfo("");
			
			DataPack p1 = new DataPack();
			p1.setCon(pts);
			p1.setOptType(dataPack.getOptType());
			serverProcessThread.getOos().writeObject(p1);
			serverProcessThread.getOos().flush();
		}
		else if ("getAll".equals(dataPack.getOptType())) {
			List<PayType> list=payTypeDao.getAll();
			int i=(int)dataPack.getCon();
			IEmployeeSevice iEmployeeSevice=new EmployeeSeviceImpl();
			List<Employee> list1=iEmployeeSevice.getAll(i);
			List<Object> list2=new ArrayList<>();
			list2.add(list);
			list2.add(list1);
			serverProcessThread.getOos().writeObject(list2);
			serverProcessThread.getOos().flush();
		}
		return null;
	}

}
